<template>
  <div>
    <!-- 导航栏 -->
    <van-nav-bar @click-left="$router.go(-1)" :title="$route.name" left-arrow />
    <!-- 商品列表 -->
    <van-card
    @click='goDetail(item.id)'
      v-for="item in goodslist"
      :key="item.id"
      :price="item.price | toPrice"
      desc="描述信息"
      :title="item.goodsname"
      :thumb="item.img? $imgUrl+item.img :'https://img01.yzcdn.cn/vant/ipad.jpeg'"
    />
  </div>
</template>

<script>
import { getCateGoods } from "../util/axios";
export default {
  data() {
    return {
      goodslist: [],
    };
  },
  mounted() {
    this.getGoodsList();
  },
  methods: {
    //封装一个获取分类列表的事件
    async getGoodsList() {
      this.goodslist = await getCateGoods({
          fid:this.$route.query.id
      });
    },
    //封装一个跳转到商品详情事件
    goDetail(id){
        this.$router.push({
            path:'/detail',
            query:{
                id
            }
        })
    }
  },
};
</script>

<style scoped></style>
